﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using ECCIT;

public partial class ForgetPwd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text="发送邮件地址：节点SendEmail value=\"63750898@qq.com\" ，发送人名称： 节点UserName value=\"艺述英国\" ，发送邮件密码：节点PassWord value=\"********\" ，smtp邮件服务器; 节点EmailServerHost value=\"smtp.qq.com\"";

    }
    protected void BtnPwd_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.Email.Text))
        {
            IList<MemberModel> list = CheckEmails(this.Email.Text);
            if (list.Count == 0)
            {
                Response.Write("<script>alert('邮箱错误或者该邮箱不存在！')</script>");
            }
            else
            {
                foreach (MemberModel model in list)
                {
                    model.ForgetPwrdM = Guid.NewGuid().ToString();
                   ResultInfo res= new MemberBLL(2052).Save(model);
                   if (res.Result)
                   {

                       string emailBody = "http://uknow.ogilvy.com.cn/UpdatePwd.aspx?Guid=" + model.ForgetPwrdM + "点击此连接重置新密码!";
                       if (sendEmail(this.Email.Text, model.Password,emailBody))
                       {
                           Response.Write("<script>alert('新密码已经发送到您的邮箱里，请注意查看！')</script>");
                       }
                   }
                }
            }
        }
        else
        {
            Response.Write("<script>alert('请输入邮箱地址')</script>");
        }
    }

    private IList<MemberModel> CheckEmails(string email)
    {
        return new MemberBLL(2052).CheckEmail(email);
    }

    private bool sendEmail(string toMail,string pwd,string emailBody)
    { 
       return MailService.sendMail(toMail, emailBody, "UKnow 艺述英国");
    }
}